/* 
 * File:   server_ColaDeEventos.cpp
 * Author: jaschu
 * 
 * Created on 22 de junio de 2014, 18:31
 */

#include <queue>
#include <iostream>
#include "common_Mutex.h"
#include "server_Evento.h"
#include "server_ColaDeEventos.h"
using std::queue;
using std::cout;
using std::endl;

ColaDeEventos::ColaDeEventos() {
    this->cola = new queue<Evento*>;    
    this->mutex = new Mutex();
}

ColaDeEventos::~ColaDeEventos() {
}

bool ColaDeEventos::estaVacia(){
    this->mutex->lock();
    if (this->cola->empty()){    
        this->mutex->unlock();
        return true;
    }
    this->mutex->unlock();
    return false;
}

void ColaDeEventos::encolar(Evento* evento){
    this->mutex->lock();
    this->cola->push(evento);
    this->mutex->unlock();
}

Evento* ColaDeEventos::mostrarPrimero(){
    this->mutex->lock();
    Evento* primero = this->cola->front();
    this->mutex->unlock();
    return primero;
}

void ColaDeEventos::desencolar(){
    this->mutex->lock();
    this->cola->pop();
    this->mutex->unlock();
}
